﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using TsTreeTimeSeries.data;
using TsTreeTimeSeries.node;
using TsTreeTimeSeries.tstree;
using Telerik.Charting;
using Telerik.WinControls;
using Telerik.WinControls.Tests;
using Telerik.WinControls.UI;
using Telerik.Windows.Controls;
using Telerik.Windows.Controls.Charting;

namespace TsTreeTimeSeries
{
    public partial class Form1 : Form
    {
        timeseriesData data = new timeseriesData();

        public char[] symbols = { 'A', 'B', 'C', 'D', 'E' };
        public string[] treeOption = {"R-tree","R*-Tree", "Ts-Tree" };
        public int[] dimensionNumber = { 3, 5, 10, 20, 30, 40, 50 };
        public int[] maxEntries = { 3, 5, 10, 20, 30 };
        public int[] minEntries = { 1, 2, 5, 10, 15 };
        public int[] pAANumber = { 2, 4, 6, 8 };

        DataTable rawData;
        public Form1()
        {
            InitializeComponent();
            InitUI();
        }

        public void InitUI()
        {
            foreach (string str in treeOption)
            {
                TreeOption.Items.Add(str);
            }
            TreeOption.SelectedIndex = 0;
            foreach (int i in dimensionNumber)
            {
                dNum.Items.Add(i);
            }
            dNum.SelectedIndex = 0;
            foreach (int i in maxEntries)
            {
                maxE.Items.Add(i);
            }
            maxE.SelectedIndex = 0;
            foreach (int i in minEntries)
            {
                minE.Items.Add(i);
            }
            minE.SelectedIndex = 0;
            foreach (int i in pAANumber)
            {
                kNum.Items.Add(i);
            }
            kNum.SelectedIndex = 0;
           
            foreach (string str in data.GetAllTables())
            {
                DataSets.Items.Add(str);
            }
        }
        // Import data from table to Objects.tsValueO ( luu cac gia tri ban dau )
      
        public void ImporData(string tableName)
        {
            rawData = data.Getdata(tableName);
            dataGridView1.DataSource = rawData.DefaultView;
            this.toolStripSoCot.Text = this.rawData.Columns.Count.ToString();
            this.toolStripSoDong.Text = this.rawData.Rows.Count.ToString();
            this.radChartView1.Series.Clear();
            this.radChartView1.GetArea<CartesianArea>().Axes.Clear();
            UpdateChart();
        }

        public void UpdateChart()
        {
            CartesianArea area = this.radChartView1.GetArea<CartesianArea>();
            area.ShowGrid = true;
            CartesianGrid grid = area.GetGrid <CartesianGrid>(); 
            //grid.DrawHorizontalStripes = true; 
            //grid.DrawVerticalStripes = true;
            //grid.DrawHorizontalFills = true;
            //grid.BorderDashStyle = System.Drawing.Drawing2D.DashStyle.DashDot;
            InitializeChartAxes();
            addAxis();
        }

        public void addAxis()
        {
            LinearAxis[] axes = this.radChartView1.Axes.Get <LinearAxis>(); 
            for (int i = 0; i < 2; i++) 
            { 
                ScatterSeries series = new ScatterSeries(); 
                series.Name = (i == 0) ? "Apartment" : "Coop"; 
                series.HorizontalAxis = axes[0]; 
                series.VerticalAxis = axes[1];
                series.DataSource = this.rawData;
                series.XValueMember = "Northland"; 
                series.YValueMember = "Auckland"; 
                series.PointSize = new SizeF(6f, 6f); 
                this.radChartView1.Series.Add(series); 
            }  
        }

        private void InitializeChartAxes() 
        {

            CartesianArea area = this.radChartView1.GetArea<CartesianArea>(); 
            LinearAxis horizontalAxis = new LinearAxis(); 
            horizontalAxis.LabelFitMode = AxisLabelFitMode.MultiLine; 
            horizontalAxis.Title = "Chiều X"; 
            horizontalAxis.Minimum = 0; 
            horizontalAxis.Maximum = 1000; 
            horizontalAxis.MajorStep = 100; 
            area.Axes.Add(horizontalAxis); 
            LinearAxis verticalAxis = new LinearAxis(); 
            verticalAxis.AxisType = AxisType.Second;
            verticalAxis.Title = "Chiều Y"; 
            verticalAxis.Minimum = 0; 
            verticalAxis.Maximum = 1000;
            verticalAxis.MajorStep = 300; 
            area.Axes.Add(verticalAxis);

        }  
        private void FormLoaded(object sender, EventArgs e)
        {
            //ImporData("AccRegNZTS");
            //PrepareData();
            //for (int i = 0; i < Objects.Count; i++)
            //{
            //    tree.InsertEntry(new Entry(Objects[i]), i, 1);
            //}

           // tree.DeleteEntry(new Entry(Objects[0]),1);
        }

        private void LoadData(object sender, MouseEventArgs e)
        {
            ImporData(DataSets.SelectedItem.ToString());
        }

        private void RunBuildTree(object sender, MouseEventArgs e)
        {
            Form2 f = new Form2(rawData, this.symbols);
            //f.rawData = this.rawData;
            f.Show();

        }

        private void propertyGrid1_Click(object sender, EventArgs e)
        {

        }

        private void toolStripStatusLabel1_Click(object sender, EventArgs e)
        {

        }
    }
}
